from typing import Dict, Type, Optional

from AIAgents.baseAgent import BaseAgent


class AgentFactory:
    """Agent工厂类，用于创建和管理不同类型的Agent"""

    _agents: Dict[str, Type[BaseAgent]] = {}

    @classmethod
    def register(cls, agent_code: str, agent_class: Type[BaseAgent]):
        """注册Agent类"""
        cls._agents[agent_code] = agent_class

    @classmethod
    def create(cls, agent_code: str, **kwargs) -> Optional[BaseAgent]:
        """创建Agent实例"""
        agent_class = cls._agents.get(agent_code)
        if agent_class:
            return agent_class(**kwargs)
        return None

    @classmethod
    def get_available_agents(cls) -> Dict[str, str]:
        """获取所有可用的Agent"""
        return {code: agent.__name__ for code, agent in cls._agents.items()}

    @classmethod
    def is_agent_available(cls, agent_code: str) -> bool:
        """检查Agent是否可用"""
        return agent_code in cls._agents
